from django.contrib import admin
from .models import ProductCategory, Product

@admin.register(ProductCategory)
class ProductCategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'parent', 'created_at', 'updated_at']
    list_filter = ['parent', 'created_at']
    search_fields = ['name']
    ordering = ['name']

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = [
        'name', 'code', 'category', 'price', 'is_active', 'created_at'
    ]
    list_filter = [
        'category', 'is_active', 'created_at'
    ]
    search_fields = ['name', 'code', 'description']
    list_editable = ['is_active']
    readonly_fields = ['created_at', 'updated_at']
    ordering = ['-created_at']
    fieldsets = (
        ('基本信息', {
            'fields': ('name', 'code', 'category', 'description')
        }),
        ('价格信息', {
            'fields': ('price',)
        }),
        ('状态信息', {
            'fields': ('is_active',)
        }),
        ('时间信息', {
            'fields': ('created_at', 'updated_at'),
            'classes': ('collapse',)
        }),
    )
